<?php

namespace Client;
/**
 * Created by PhpStorm.
 * User: 554665488
 * Date: 2018-6-28
 * Time: 18:32
 * @description:同步客户端
 * @Author: yfl
 * @QQ 554665488
 */

class clientTcpRequest
{
    private $client;
    private $ip;
    private $port;

    public function __construct($ip, $port)
    {
        $this->ip = $ip;
        $this->port = $port;
        $this->client = new \Swoole\Client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_SYNC);
    }

    //同步请求客户端
    public function sync($data)
    {
        if ($this->client->connect($this->ip, $this->port)) {
            $this->client->send($data); //发送
            $data = $this->client->recv();//接收数据
            $this->client->close();
            return $data;
        }

    }
}